export enum VisualEditorPropsType {
    input = 'input',
    color = 'color',
    select = 'select'
}

export interface SelectOption {
    value: string | number;
    label: string | number
}

export type VisualEditorProps = {
    type: VisualEditorPropsType;
    label: string;
    value:string|number;
} & {
    selectOptions?: SelectOption[]
}

/**
 * 通用的
 * @param label
 */
export function createEditorGeneralProp<T extends string | number>(type: VisualEditorPropsType,
                                                                   label: string,
                                                                   defaultValue: T | string = ''): VisualEditorProps {
    return {
        type,
        label,
        value:defaultValue
    }
}

/**
 * input
 * @param label
 */
export function createEditorInputProp(label: string, defaultValue:string): VisualEditorProps {
    return createEditorGeneralProp<string>(VisualEditorPropsType.input, label,defaultValue)
}

/**
 * color
 * @param label
 */
export function createEditorColorProp(label: string): VisualEditorProps {
    return createEditorGeneralProp(VisualEditorPropsType.color, label)
}

/**
 * select
 * @param label
 */
export function createEditorSelectProp(label: string, defaultValue:string, selectOptions:SelectOption[]): VisualEditorProps {
    return {
        ...createEditorGeneralProp(VisualEditorPropsType.select, label),
        selectOptions,
        value:defaultValue
    }
}

